package com.yicong.ants.bean.base;

import com.yicong.ants.bean.common.PageInfoBean;

import java.util.ArrayList;
import java.util.List;

/**
 * description 服务器响应的数据,
 *
 * 注意， okHttpManager 会修改响应的结构，将如下的 scenicList 改成 list
 * {
 * 	"code": 2000,
 * 	"msg": "请求成功",
 * 	"time": "1582272804",
 * 	"data": {
 * 		"pageInfo": {
 * 			"curPage": "1",
 * 			"nextPage": 2,
 * 			"countPage": 300
 *           },
 * 		"scenicList": [{
 * 	   }]
 * 	 }
 * }
 *
 **/
public class PageRespBean<T> extends BaseBean {

    Data<T> data;

    public PageRespBean() {
    }

    public PageInfoBean getPageInfo() {
        return data.getPageInfo();
    }

    public List<T> getList() {
        return data.getList();
    }

    public Data<T> getData() {
        return this.data;
    }

    public void setData(Data<T> data) {
        this.data = data;
    }

    public boolean equals(final Object o) {
        if (o == this) return true;
        if (!(o instanceof PageRespBean)) return false;
        final PageRespBean<?> other = (PageRespBean<?>) o;
        if (!other.canEqual((Object) this)) return false;
        if (!super.equals(o)) return false;
        final Object this$data = this.getData();
        final Object other$data = other.getData();
        if (this$data == null ? other$data != null : !this$data.equals(other$data)) return false;
        return true;
    }

    protected boolean canEqual(final Object other) {
        return other instanceof PageRespBean;
    }

    public int hashCode() {
        final int PRIME = 59;
        int result = super.hashCode();
        final Object $data = this.getData();
        result = result * PRIME + ($data == null ? 43 : $data.hashCode());
        return result;
    }

    public String toString() {
        return "PageRespBean(data=" + this.getData() + ")";
    }

    public static class Data<T> {
        public PageInfoBean pageInfo = new PageInfoBean();
        // 注意，okHttpManager 会修改响应的字段名，改成 list 便于统一处理
        private List<T> list = new ArrayList<>();

        public Data() {
        }

        public PageInfoBean getPageInfo() {
            return this.pageInfo;
        }

        public List<T> getList() {
            return this.list;
        }

        public void setPageInfo(PageInfoBean pageInfo) {
            this.pageInfo = pageInfo;
        }

        public void setList(List<T> list) {
            this.list = list;
        }

        public boolean equals(final Object o) {
            if (o == this) return true;
            if (!(o instanceof PageRespBean.Data)) return false;
            final Data<?> other = (Data<?>) o;
            if (!other.canEqual((Object) this)) return false;
            final Object this$pageInfo = this.getPageInfo();
            final Object other$pageInfo = other.getPageInfo();
            if (this$pageInfo == null ? other$pageInfo != null : !this$pageInfo.equals(other$pageInfo))
                return false;
            final Object this$list = this.getList();
            final Object other$list = other.getList();
            if (this$list == null ? other$list != null : !this$list.equals(other$list))
                return false;
            return true;
        }

        protected boolean canEqual(final Object other) {
            return other instanceof PageRespBean.Data;
        }

        public int hashCode() {
            final int PRIME = 59;
            int result = 1;
            final Object $pageInfo = this.getPageInfo();
            result = result * PRIME + ($pageInfo == null ? 43 : $pageInfo.hashCode());
            final Object $list = this.getList();
            result = result * PRIME + ($list == null ? 43 : $list.hashCode());
            return result;
        }

        public String toString() {
            return "PageRespBean.Data(pageInfo=" + this.getPageInfo() + ", list=" + this.getList() + ")";
        }
    }

    /**
     * 测试数据
     */
    public static <T> PageRespBean<T> newSucTestResp(int page) {
        PageRespBean<T> respBean = new PageRespBean<>();
        respBean.setCode("2000");
        respBean.setData(new Data<>());
        respBean.getPageInfo().setCurPage(page);
        respBean.getPageInfo().setCountPage(1000);
        return respBean;
    }
}
